package com.baihan.angus.app.game.busshow.pop_dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.utils.AppUtil;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.busshow.adps.MyAnswerAdp;
import com.baihan.angus.app.game.common.bean.response.ScriptStepResponse;

import java.util.List;

public class MyAnswerDialog extends Dialog {

    private Context mContext;
    private WindowManager.LayoutParams mLayoutParams;
    private LinearLayout llClose;
    private RecyclerView rvMyAnswer;

    private MyAnswerAdp mMyAnswerAdp;

    public MyAnswerDialog(@NonNull Context context) {
        super(context, R.style.FullDialog);
        this.mContext = context;
        initContentView();
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        Window dialogWindow = this.getWindow();
        mLayoutParams = dialogWindow.getAttributes();
        mLayoutParams.width = AppUtil.getScreenWidth(context);
        mLayoutParams.height = AppUtil.getScreenHeight(context);
        dialogWindow.setAttributes(mLayoutParams);
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
        dialogWindow.getDecorView().setBackgroundResource(R.color.dialog_bg);
        dialogWindow.setGravity(Gravity.BOTTOM);
    }

    private void initContentView() {
        View dialogView = LayoutInflater.from(this.getContext()).inflate(R.layout.dialog_my_answer, (ViewGroup) null);
        setContentView(dialogView);
        llClose = dialogView.findViewById(R.id.llClose);
        rvMyAnswer = dialogView.findViewById(R.id.rvMyAnswer);

        mMyAnswerAdp = new MyAnswerAdp();
        rvMyAnswer.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
        mMyAnswerAdp.bindToRecycleView(rvMyAnswer);

        llClose.setOnClickListener(v -> {
            cancel();
        });
    }

    public void initData(List<ScriptStepResponse.DataX.Question.Data> data) {
        mMyAnswerAdp.addAll(data);
    }
}
